﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Text.RegularExpressions;

using Microsoft.Xna.Framework.Content;

namespace GameDataLibrary.Script
{
    public class Script
    {
        string scriptText;

        public string ScriptText
        {
            get { return scriptText; }
            set { this.scriptText = value; }
        }



        public Script()
        {
            scriptText = "";
        }

        public Script( List<string> script,ScriptContent scriptContextSetting)
        {
 
        }

        public List<ObjectCMD> KRKRScriptProcessor(string script)
        {
            List<ObjectCMD> scriptList = new List<ObjectCMD>();
            string[] scripts = script.Split('\n');
            foreach(string str in scripts)
            {
                //read a line of script
                scriptList.Add(GetScriptObject(str));
            }
            


            return scriptList;
        }

        private ObjectCMD GetScriptObject(string str)
        {
            Regex script = new Regex("[w]");
            if (script.IsMatch(str.ToLower()))
            {
                return new ObjectCMD(ScriptCMD.Script, str.Split('[')[0]);
            }
            return new ObjectCMD();
        }


    }

    public class ScriptReader : ContentTypeReader<Script>
    {
        protected override Script Read(ContentReader input, Script script)
        {
            if (script == null)
            {
                script = new Script();
            }

            script.ScriptText = input.ReadString();

            return script;
        }
    }



    public enum ScriptCMD
    {
        None,
        Script,
        PlayBGM,

    }

    public class ObjectCMD
    {
        ScriptCMD cmdType;
        string args;

        public ObjectCMD()
        {
            cmdType = ScriptCMD.None;
            args = "";
        }

        public ObjectCMD(ScriptCMD scriptCMD, string script)
        {
            cmdType = scriptCMD;
            args = script;
        }
    }
}
